/*
 *  AComponent.cpp
 *  libavid
 *
 *  Created by Peter on 23.02.12.
 *  Copyright 2012 __MyCompanyName__. All rights reserved.
 *
 */

#include "AComponent.h"
#include "AStream.h"
#include "AObjDoc.h"

A_IMPLEMENT_CLASS( 'COMP', AComponent, AObject );

void AComponent::readFromStream( AStream& str, const AObjDoc& objd )
{
	// Our safety net tells us that's the size difference, will only work if 
	// there is no variable-length field like a name
	//str.skip( 41 );

	UInt8 tagMark, version;
	str.readPod( tagMark );
	str.readPod( version );
	
	TR_ASSERT( tagMark == 0x02 );
	TR_ASSERT( version == 0x03 );
	
	str.readPod( _leftBob );
	str.readPod( _rightBob );
	str.readPod( _trackKind );
	str.readPod( _edRateMantissa );
	str.readPod( _edRateExp10 );
 
	_name = str.readString();
	_effectId = str.readString();

	UInt32 attributesRef;
	UInt32 sessionAttrsRef;
	str.readPod( attributesRef );
    str.readPod( sessionAttrsRef );
	
	_attributes   = objd.resolveRef< AAttrList >( attributesRef );
	_sessionAttrs = objd.resolveRef< AAttrList >( sessionAttrsRef );
	
    str.readPod( _precomputed );
 
	// Minor version subchunk whatever going on here, probably part of the
    // object that stores the reference that follows
	str.readPod( tagMark );
	str.readPod( version );
	TR_ASSERT( tagMark == 0x01 );
	TR_ASSERT( version == 0x01 );
	str.readPod( tagMark );
	TR_ASSERT( tagMark == 72 );
 
	str.readPod( _paramList );
}

#define TRACE_FIELD( x ) "\t" #x ": " << x << std::endl

void AComponent::dump( std::ostream& str ) const
{
	str << "AComponent {" << std::endl;
	str << TRACE_FIELD( _leftBob );
	str << TRACE_FIELD( _rightBob );
	str << TRACE_FIELD( _trackKind );
	str << TRACE_FIELD( _edRateMantissa );
	str << TRACE_FIELD( _edRateExp10 );
	str << TRACE_FIELD( _name );
	str << TRACE_FIELD( _effectId );
	str << TRACE_FIELD( _attributes );
	str << TRACE_FIELD( _sessionAttrs );
	str << TRACE_FIELD( _precomputed );
	str << TRACE_FIELD( _paramList );
	str << "}" << std::endl;
}